
<!-- saved from url=(0043)http://localhost:8080/EMIS/purchase_add.jsp -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="Bookmark" href="http://localhost:8080/favicon.ico">
<link rel="Shortcut Icon" href="http://localhost:8080/favicon.ico">
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="H-ui.min.css">
<link rel="stylesheet" type="text/css" href="H-ui.admin.css">
<link rel="stylesheet" type="text/css" href="iconfont.css">
<link rel="stylesheet" type="text/css" href="icheck.css">
<link rel="stylesheet" type="text/css" href="skin.css" id="skin">
<link rel="stylesheet" type="text/css" href="style.css">
	
<link rel="stylesheet" type="text/css" href="jquery-ui-1.9.2.custom.css">
<title>添加采购信息</title>

<script type="text/javascript" src="jquery.min.js"></script><script type="text/javascript" src="jquery-ui-1.9.2.custom.min.js"></script><link rel="stylesheet" href="layer.css" id="layui_layer_skinlayercss"><link href="WdatePicker.css" rel="stylesheet" type="text/css"></head>




<body>
	<article class="page-container">
		<form action="http://localhost:8080/EMIS/addpurchase" name="form" method="post" class="form form-horizontal" id="form" onSubmit="">

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>合同数字编号：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="contractnum" name="contractnum" style="width:350px">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>备件名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="spare" name="spare" style="width:350px"><span id="aaa"></span>
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>规格型号：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="model" name="model" style="width:350px">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>计量单位：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="prickle" name="prickle" style="width:350px">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>数量：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="amount" name="amount" style="width:350px">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>单价：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="price" name="price" style="width:350px">
				</div>

			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>供货商名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="supplier" name="supplier" style="width:350px">
				</div>
			</div>
			
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>采购时间：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" name="purdate" style="width:150px;" onFocus="WdatePicker({maxDate:&#39;%y-%M-%d&#39;})" id="purdate" class="input-text Wdate">
				</div>
			</div>

			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" id="send" type="" onClick="test()" value="  提交  ">
						
				</div>
			</div>
		</form>
	</article>

	

	<script type="text/javascript" src="jquery.min.js"></script>
	<script type="text/javascript" src="layer.js"></script>
	<script type="text/javascript" src="laypage.js"></script>
	<script type="text/javascript" src="jquery.icheck.min.js"></script>
	<script type="text/javascript" src="WdatePicker.js"></script>
	<script type="text/javascript" src="jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="jquery.validate.min.js"></script>
	<script type="text/javascript" src="validate-methods.js"></script>
	<script type="text/javascript" src="messages_zh.min.js"></script>
	<script type="text/javascript" src="H-ui.js"></script><a href="javascript:void(0)" class="Hui-iconfont toTop" title="返回顶部" alt="返回顶部" style="display:none"></a>
	<script type="text/javascript" src="H-ui.admin.js"></script>

	<script type="text/javascript" src="jquery-ui-1.9.2.custom.min.js"></script>

	<script type="text/javascript">
	$(function(){ 
			//文本框失去焦点后
			$('form :input').blur(function() {
								var $parent = $(this).parent();
								$parent.find(".formtips").remove();
								//验证合同数字编号 
								if ($(this).is('#contractnum')) {
									 if (this.value == ""|| this.value.length != 6|| isNaN(this.value) == true) {
										var errorMsg = '请输入6位的合同数字编号.';
										$parent.append('<span class="formtips onError" style="color:red">'+ errorMsg + '</span>');
									} else if(this.value.trim()=="" || this.value.replace(/(^s*)|(s*$)/g, "").length ==0){
										var errorMsg = '输入内容不能为空格';
										$parent.append('<span class="formtips onError" style="color:red">'+ errorMsg + '</span>');
									} else {
										//var okMsg = '输入正确.'; 
										$parent.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}
								//验证备件 
								if ($(this).is('#spare')) {
									if (this.value == "") {
										var errorMsg = '备件名称不能为空.';
										$parent.append('<span class="formtips onError" style="color:red">'+ errorMsg + '</span>');
									} else if(this.value.trim()==""){
										var errorMsg = '输入内容不能为空格';
										$parent.append('<span class="formtips onError" style="color:red">'+ errorMsg + '</span>');
									}
									else {
										//document.getElementById("aaa").innerHTML="<image src="h-ui-images/ok.png">";
										//var okMsg = "输入正确！" 
										//okMsg.innerHTML = <img src="images/hi.png"/>;
										//return true;
										$parent.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}

								//验证规格型号 
								if ($(this).is('#model')) {
									if (this.value == "") {
										var errorMsg = '规格型号不能为空.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									}else if(this.value.trim()==""){
									var errorMsg = '输入内容不能为空格';

										$parent.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									}else{
										$parent
												.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}

								//验证计量单位 
								if ($(this).is('#prickle')) {
									if (this.value == "") {
										var errorMsg = '计量单位不能为空.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else if(this.value.trim()==""){
										var errorMsg = '输入内容不能为空格';

										$parent.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									}
									else {
										//var okMsg = '输入正确.'; 
										$parent
												.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}

								//验证数量
								if ($(this).is('#amount')) {
									if (this.value == "") {
										var errorMsg = '数量不能为空.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else if (isNaN(this.value) == true) {
										var errorMsg = '数量必须为数字.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else {
										//var okMsg = '输入正确.'; 
										$parent
												.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}

								//验证单价 
								if ($(this).is('#price')) {
									if (this.value == "") {
										var errorMsg = '单价不能为空.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else if (isNaN(this.value) == true) {
										var errorMsg = '单价必须为数字.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else {
										//var okMsg = '输入正确.'; 
										$parent
												.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}

								//验证合同总额 
								if ($(this).is('#contracttotal')) {
									if (this.value == "") {
										var errorMsg = '合同总额不能为空.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else if (isNaN(this.value) == true) {
										var errorMsg = '合同总额必须为数字.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else if(this.value.trim()==""){
										var errorMsg = '输入内容不能为空格';

										$parent.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									}
									else {
										//var okMsg = '输入正确.'; 
										$parent
												.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}

								//验证供货商名称
								if ($(this).is('#supplier')) {
									if (this.value == "") {
										var errorMsg = '供货商名称不能为空.';
										$parent
												.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									} else if(this.value.trim()==""){
										var errorMsg = '输入内容不能为空格';

										$parent.append('<span class="formtips onError" style="color:red">'
														+ errorMsg + '</span>');
									}
									else {
										//var okMsg = '输入正确.'; 
										$parent
												.append('<span class="formtips onSuccess" style="color:green"></span>');
									}
								}
								
								if( $(this).is('#purdate') ){ 
               						if( this.value==""  ){ 
                     					var errorMsg = '日期不能为空.'; 
                    					$parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               						}
               						else{ 
                     					$parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
               						}
           			 			} 
							})
					.keyup(function() {
						$(this).triggerHandler("blur");
						$('#model').unbind("keyup");
					})
					.focus(function() {
						$(this).triggerHandler("blur");
						$('#model').unbind("focus");
					}
					);//end blur

			//提交，最终验证。 
			$('#send').click(function() {
		  $("form :input.required").trigger('blur');
		  var numError=$("form .onError").length;
		  if(numError!=0){
		  	  return false;
		  }
		  else{
		  	return true;
		  }
		 
     });
		})
	</script>
	
	<script type="text/javascript">
$(function() {
			$("#dialog-confirm").dialog({
				autoOpen: false,
				title : '系统提示',
				height: 190,
				width: 390,
				modal: false,
				resizable: false,
				draggable: false,
				buttons: {
					"确定": function() {
						$( this ).dialog( "close" );
					}
				}
			});
	 });
function test(){

	//验证为空
	for(var i=0;i<document.form.elements.length;i++)
         {
          if(document.form.elements[i].value=="" || document.form.elements[i].value.trim()=="")
          {
           document.form.elements[i].focus();
           return false;
          }
         }
   var contractnum = $('#contractnum').val();
   var spare = $('#spare').val();
   var model = $('#model').val();
	$.ajax({
		type : "POST",//ajax请求数据的方式   默认为get  post   还有put  delete  分别对应增删改查
		url :"/EMIS/addpurchaseservlet3",//servlet的地址，web.xml中配置  项目名+servlet的地址
		dataType : "html",//请求的数据格式  json或者xml
		data :{//传输的数据，以键值对方式传输，会根据datatype的类型自动转成xml或者json数据格式传输
	    contractnum : contractnum,
		spare : spare,
		model : model
		 },
		success :function(data){//data里面存放的是后台处理后返回到前台的数据 eg：success 或者 error等。
		console.log(data);
		if(data == "合同明细内没有此信息"){
		$("#dialog-confirm .text").html(data);
		
		$("#dialog-confirm").dialog("open");
		
		 } else {
		 	$("#form").submit();
		 }
		}
	});

}
</script> 

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-dialog-buttons" tabindex="-1" role="dialog" aria-labelledby="ui-id-1" style="display: none; outline: 0px; z-index: 1000;"><div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span id="ui-id-1" class="ui-dialog-title">系统提示</span><a href="http://localhost:8080/EMIS/purchase_add.jsp#" class="ui-dialog-titlebar-close ui-corner-all" role="button"><span class="ui-icon ui-icon-closethick">close</span></a></div><div id="dialog-confirm" style="" class="ui-dialog-content ui-widget-content">
		<p>
			<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
			<span class="text"></span></p>
	</div><div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><div class="ui-dialog-buttonset"><button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">确定</span></button></div></div></div></body></html>